using System;
using jSLApp.Client.MainService;
using jSLCore.Client.Presentation.Authorization;
using jSLCore.Utility.Extensions;

namespace jSLApp.Client.Workflow
{
    /// <summary>
    /// use this class to declare form logic
    /// </summary>
    public static class DataHelper
    {
        public static string MusicToTrackLength(this Music music)
        {
            var formatTxt = jConstants.GetEnumDescription(music.FileFormat).Name;
            return string.Format("{0}",TimeSpan.FromSeconds(music.Length).ToHHMMSS());
        }

        public static bool IsAllowedToChangeMusic(this string who)
        {
            if (who == null) return false;

            if (!jSecurity.IsAuthorized) return false;

            return (jSecurity.Login.ToUpper().Trim() == who.ToUpper().Trim()) || (Security.SecurityBinding.HasPermission(Permission.AlienTrackChange)) || (Security.SecurityBinding.HasPermission(Permission.AlienTrackDelete));
        }

         public static bool IsCurrentAuthor(this string who)
         {

             if (!jSecurity.IsAuthorized) return false;
             return (jSecurity.Login.ToUpper().Trim() == who.ToUpper().Trim());
         }
    }
}